﻿using System.Text;
using System.Collections.Specialized;
using Newtonsoft.Json;

namespace CometDocs
{
    internal partial class Client
    {
        /// <summary>
        /// Get the list of notifications for the connected user: https://www.cometdocs.com/developer/apiDocumentation#method-getNotifications
        /// </summary>
        /// <param name="token">A valid authentication token.</param>
        /// <returns>An array of notifications.</returns>
        public Notification[] GetNotifications(AuthenticationToken token)
        {
            NameValueCollection @params = new NameValueCollection(1);
            @params.Add("token", token.Value);

            byte[] result = webClient.UploadValues(APIRoot + "getNotifications", @params);

            string json = Encoding.ASCII.GetString(result);

            GetNotificationsResponse response = JsonConvert.DeserializeObject<GetNotificationsResponse>(json);

            CheckAndThrow(response);

            return response.Notifications;
        }
    }
}
